﻿namespace SPWikiProvisioning.Helpers
{
    #region Usings

    using System.Linq;
    using System.Text.RegularExpressions;

    #endregion

    internal static class FeatureHelper
    {
        public static string ParseProvisioningProperties(string definition)
        {
            var localizationHelper = new LocalizationHelper();

            var matches = Regex.Matches(definition, "\\$Resources:(\\w+),(\\w+);");
            definition = (from Match match in matches
                            let found = match.Groups[0].ToString()
                            let defaultResourceFile = match.Groups[1].ToString()
                            let key = match.Groups[2].ToString()
                            select found).Aggregate(definition, (current, found) => current.Replace(found, localizationHelper.GetLocalizedLiteral(found)));

            return definition;
        }

        public static string ParseProvisioningProperties(string definition, uint language)
        {
            var localizationHelper = new LocalizationHelper();

            var matches = Regex.Matches(definition, "\\$Resources:(\\w+),(\\w+);");
            definition = (from Match match in matches
                          let found = match.Groups[0].ToString()
                          let defaultResourceFile = match.Groups[1].ToString()
                          let key = match.Groups[2].ToString()
                          select found).Aggregate(definition, (current, found) => current.Replace(found, localizationHelper.GetLocalizedLiteral(found, language)));

            return definition;
        }
    }
}
